<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="/app/admin/component/layui/css/layui.css?v=2.8.12" />
    <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
    <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
</head>

<body class="pear-container">
    <style>
        .layui-input-block input {
            width: 300px;
        }
    </style>

    <div class="layui-card">
        <div class="layui-card-body">

            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">基本信息</li>
                    <li>更多信息</li>
                </ul>
                <div class="layui-tab-content">

                    <!-- 基本信息 -->
                    <div class="layui-tab-item layui-show">

                        <form class="layui-form" lay-filter="baseInfo">
                            <div class="layui-form-item">
                                <label class="layui-form-label">网站标题</label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" required lay-verify="required" placeholder="请输入网站标题"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">网站关键字</label>
                                <div class="layui-input-block">
                                    <input type="text" name="keyword" placeholder="请输入网站关键字" autocomplete="off"
                                        class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">网站描述</label>
                                <div class="layui-input-block">
                                    <input type="text" name="description" placeholder="请输入网站描述" autocomplete="off"
                                        class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">API</label>
                                <div class="layui-input-block">
                                    <input type="text" name="api" required lay-verify="required" placeholder="请输入后端链接，如:http://127.0.0.1:8787" autocomplete="off"
                                        class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">网站二维码</label>
                                <div class="layui-input-block">
                                    <img class="img-3" src="" />
                                    <input type="text" style="display:none" name="qrcode" value="" />
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm" id="qrcode"
                                        permission="app.admin.upload.avatar">
                                        <i class="layui-icon layui-icon-upload"></i>上传图片
                                    </button>
                                    <button type="button" class="pear-btn pear-btn-primary pear-btn-sm"
                                        id="attachment-choose-qrcode" permission="app.admin.upload.attachment">
                                        <i class="layui-icon layui-icon-align-left"></i>选择图片
                                    </button>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">ICP备案号</label>
                                <div class="layui-input-block">
                                    <input type="text" name="icp" placeholder="请输入ICP备案号" autocomplete="off"
                                        class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
                                        lay-filter="saveBaseInfo">
                                        提交
                                    </button>
                                    <button type="reset" class="pear-btn pear-btn-md">
                                        重置
                                    </button>
                                </div>
                            </div>
                        </form>

                    </div>

                    <!-- 更多信息 -->
                    <div class="layui-tab-item">
                        <form class="layui-form" lay-filter="baseInfo">
                            <div class="layui-form-item">
                                <label class="layui-form-label">小标题</label>
                                <div class="layui-input-block">
                                    <input type="text" name="min_title" required lay-verify="required"
                                        placeholder="请输入网站小标题" value="KingBes" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">GITHUB</label>
                                <div class="layui-input-block">
                                    <input type="text" name="github" placeholder="请输入GITHUB主页" autocomplete="off"
                                        class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">GITEE</label>
                                <div class="layui-input-block">
                                    <input type="text" name="gitee" placeholder="请输入GITEE主页" autocomplete="off"
                                        class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">QQ</label>
                                <div class="layui-input-block">
                                    <input type="text" name="qq" required lay-verify="required" placeholder="请输入QQ"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">微信</label>
                                <div class="layui-input-block">
                                    <input type="text" name="wechat" required lay-verify="required" placeholder="请输入微信"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
                                        lay-filter="saveBaseInfo">
                                        提交
                                    </button>
                                    <button type="reset" class="pear-btn pear-btn-md">
                                        重置
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
            </div>

        </div>
    </div>


    <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
    <script src="/app/admin/component/pear/pear.js"></script>
    <script src="/app/admin/admin/js/permission.js"></script>
    <script>

        layui.use(["form", "popup"], function () {
            let form = layui.form;
            let $ = layui.$;

            $.ajax({
                url: "/app/kb_blog/admin/info/get",
                dataType: "json",
                success: function (res) {
                    form.val("baseInfo", res.data);
                    $("#qrcode").prev().val(res.data.qrcode).prev().attr("src", res.data.qrcode);
                }
            });

            // qrcode
            /* let input = $("#qrcode").prev();
            input.prev().attr("src", input.val()); */
            layui.$("#attachment-choose-qrcode").on("click", function () {
                parent.layer.open({
                    type: 2,
                    title: "选择附件",
                    content: "/app/admin/upload/attachment?ext=jpg,jpeg,png,gif,bmp",
                    area: ["95%", "90%"],
                    success: function (layero, index) {
                        parent.layui.$("#layui-layer" + index).data("callback", function (data) {
                            input.val(data.url).prev().attr("src", data.url);
                        });
                    }
                });
            });
            layui.upload.render({
                elem: "#qrcode",
                url: "/app/admin/upload/avatar",
                acceptMime: "image/gif,image/jpeg,image/jpg,image/png",
                done: function (res) {
                    if (res.code) {
                        return layui.popup.failure(res.msg);
                    }
                    this.item.prev().val(res.data.url).prev().attr("src", res.data.url);
                }
            });

            form.on("submit(saveBaseInfo)", function (data) {
                $.ajax({
                    url: "/app/kb_blog/admin/info/save",
                    dataType: "json",
                    type: "POST",
                    data: data.field,
                    success: function (res) {
                        if (res.code) {
                            return layui.popup.failure(res.msg);
                        }
                        return layui.popup.success("操作成功");
                    }
                });
                return false;
            });

        });

    </script>

</body>

</html>